package org.neframework.webtest.action.xyk.bank;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.neframework.webtest.action_rest.UploadTools;
import org.neframework.webtest.base.BaseController;
import org.neframework.webtest.model.t_s_bank;
import org.neframework.webtest.service.BankService;

import com.tmsps.neframework.core.utils.JsonTools;
import com.tmsps.neframework.mvc.annotation.Controller;
import com.tmsps.neframework.mvc.annotation.RequestMapping;
import com.tmsps.neframework.mvc.annotation.ResponseBody;
import com.tmsps.neframework.mvc.plugin.Tip;

@Controller
@RequestMapping("/cp/xyk/bank")
public class BankController extends BaseController {

	private static final BankService bankService = new BankService();

	@RequestMapping("/list")
	public String list() {
		return "/jsp/xyk/bank/list.jsp";
	}

	@RequestMapping("/list_data")
	@ResponseBody
	public void list_data(String srh_name) {

		List<Map<String, Object>> list = bankService.selectBankList(srh_name,
				sort_params, page);

		result.put("list", list);
	}

	@RequestMapping("/add")
	@ResponseBody
	public void add(t_s_bank bank) throws IOException {
		Map<String, String> map = UploadTools.upload(req, oc);
		bank.setFile_id(map.get("file_id"));
		bank.setName(map.get("bank.name"));
		bank.setUrl_bk(map.get("bank.url_bk"));
		bank.setUrl_te(map.get("bank.url_te"));
		oc.saveObj(bank);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

	@RequestMapping("/edit_form")
	@ResponseBody
	public String edit_form(String kid) {
		t_s_bank bank = (t_s_bank) oc.findObjById(kid, t_s_bank.class);

		Map<String, Object> map1 = JsonTools.objToMap("bank", bank);

		return JsonTools.toJson(map1);
	}

	@RequestMapping("/edit")
	@ResponseBody
	public void edit(t_s_bank bank) {
		t_s_bank bankDb = (t_s_bank) oc.findObjById(bank.getKid(),
				t_s_bank.class);
		bankDb.setName(bank.getName());
		bankDb.setFile_id(bank.getFile_id());
		bankDb.setUrl_bk(bank.getUrl_bk());
		bankDb.setUrl_te(bank.getUrl_te());
		oc.updateObj(bankDb);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

	@RequestMapping("/del")
	@ResponseBody
	public void del(String kid) {
		oc.delObjById(kid, t_s_bank.class);

		this.setTipMsg(true, "删除成功!", Tip.Type.success);
	}

}
